<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>融资机构列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<script type="text/javascript">
	var grid = null;
	var _mfrId;
	$(function () {
		   $("#insUseCdNm").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
           	   data: [
	                {  name: 'key', width: 100}, 
	                {  name: 'value', width: 120},
	               ],
	            url:'<%=path%>/rfbase/fribaseinfo/getInsUseCd.do',
	            ajaxType :'GET',
	            slide: false,
	            valueField: 'key', textField: 'value',
	            valueFieldID: 'insUseCd'
           }); 
		   
		var _url = '<%=path%>/rfbase/fribaseinfo/initList.do' ;
	    $("#ligergrid1").ligerGrid({
	    	url: _url,
	    	method : 'get',
	        columns: [
	            { display: '融资机构名称', name: 'fundRasInsNm', align:'center', width: 150 },
	            { display: '机构状态', name: 'insStsNm', align:'center', width: 80 },
	            { display: '融资机构用途', name: 'insUseCdNm', align:'center', width: 100 },
	            { display: '业务线', name: 'bussinessLineNm', align:'center', width: 70},
	            { display: '授信状态', name: 'crStNm', align:'center', width: 100 },
	            { display: '授信起始日期', name: 'stDt',align:'center', width: 100,render:renderDate},
	            { display: '授信结束日期', name: 'edDt',align:'center', width: 100,render:renderDate},
	            { display: '授信额度', name: 'crLmt',align:'center', width: 110,render: commafy},
	            { display: '实际使用额度', name: 'useLmt',align:'center', width: 110,render: commafy },
	            { display: '余额', name: 'crBal',align:'center', width: 110,render: commafy },
	            { display: '操作', width: 320 ,height:'100px', align:'center',
	            	render: function (rowdata, rowindex, value){
	            		var h='<a href="javascript:showDetail(';
	            		h+="'"+rowdata.id+"'";
	                    h+=')">查看</a>';
		                //未审核
	                    if(rowdata.insSts == 0){
	                    	h+=' | ';
		                    h+='<a href="javascript:modifyRow(';
		            		h+="'"+rowdata.id+"'";
		                    h+=')">修改</a>';
		                    h+=' | ';
		                    h+='<a href="javascript:startFlow(';
		                    h+="'"+rowdata.id+"'";
		                    h+=')">审核</a>';
	                    }
	                    // 正常
		                if(rowdata.insSts == 1){
		                	h+=' | ';
		                    h+='<a href="javascript:modifyBankRow(';
		            		h+="'"+rowdata.id+"'";
		                    h+=')">追加帐户信息</a>';
	                	  	h+=' | ';
		                    h+='<a href="javascript:searchCr(';
		                    h+="'"+rowdata.id+"'";
		                    h+=')">查看授信</a>';
		                    h+=' | ';
		                    h+='<a href="javascript:searchScm(';
		            		h+="'"+rowdata.id+"'";
		                    h+=')">查看报价</a>';
		                }
		                <sys:funcAuth resCd="fribaseinfo_view">
			                h+=' | ';
		                    h+='<a href="javascript:modifyDetail(';
		            		h+="'"+rowdata.id+"'";
		                    h+=')">维护机构详情</a>';
	                    </sys:funcAuth>
	                	return h;
	            	}
	            },
	        ],
	        pageSize:10,
	    	checkbox: true,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        rownumbers:true,
	        fixedCellHeight:false,
	        /* isChecked: f_isChecked, onCheckRow: f_onCheckRow, onCheckAllRow: f_onCheckAllRow */
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         var insUseCd = $("#insUseCd").val();
        	 data["insUseCd"]=insUseCd;
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	    
	});
<%-- 	//删除数据
	function deleteRow(_id){
		if(!_id)return;
		var _ids = [];
		_ids.push(_id);
		$.ligerDialog.confirm('确定删除吗?', function (flag) {
			if(flag == false)return;
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/rfbase/fribaseinfo/remove.do?id='+_id,
				beforeSend: function(){
			          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			     },
				success:function(msg){
					wait_dialog.close();
					 if(msg.success == 1){
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 grid.reload();
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
		});
	} --%>
  	
  	//修改方法
  	function modifyRow(_id){
        $.ligerDialog.SQopen({
            cls: 'noBorder_Dialog',
            width: 1300,
            height:450,
            title : '修改融资机构',
            url:'<%=path%>/rfbase/fribaseinfo/toAddPage.do?id='+_id,
        });
  	}
  	
  	//修改方法
  	function modifyBankRow(_id){
        $.ligerDialog.SQopen({
            cls: 'noBorder_Dialog',
            width: 1300,
            height:400,
            title : '追加帐户信息',
            url:'<%=path%>/rfbase/fribaseinfo/toAddBankPage.do?id='+_id,
        });
  	}

  	//新增
	function add(){
		$.ligerDialog.SQopen({
            cls: 'noBorder_Dialog',
            width: 1300,
            height:450,
            title : '新增融资机构',
            url:'<%=path%>/rfbase/fribaseinfo/toAddPage.do'
        });
	}
	
	//查看详情
	function showDetail(_id){
		$.ligerDialog.SQopen({
            cls: 'noBorder_Dialog',
            width: 1000,
            height:450,
            title : '融资机构详情',
            url:'<%=path%>/rfbase/fribaseinfo/toDetailPage.do?tabFlag=101&id='+_id,
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [ {
                    text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no', 
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
            ]
        });
	}
	
	//融资机构-添加授信
	function addCr(){
		var selectedRows = grid.getSelectedRows();
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
            return;
        }
		if(selectedRows[0].insSts != 1){
			$.ligerDialog.SQalert({content: "选择的机构状态必须为正常！", SQ_type: "warning"});
            return;
		}     
		$.ligerDialog.SQopen({
            cls: 'noBorder_Dialog',
            width: 1200,
            height:500,
            title : '融资机构-添加授信',
           url:'<%=path%>/rfbase/crbaseinfo/toAddPage.do?fncInsId='+selectedRows[0].id,
        });
	}
	
	//融资机构-添加融资报价
	function addScm(){
		var selectedRows = grid.getSelectedRows();
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
            return;
        }
		if(selectedRows[0].insSts != 1){
			$.ligerDialog.SQalert({content: "选择的机构状态必须为正常！", SQ_type: "warning"});
            return;
		}
		$.ligerDialog.SQopen({
            cls: 'noBorder_Dialog',
            width: 1100,
            height:500,
            title : '融资机构-添加融资报价',
            url:'<%=path%>/rfbase/scmbaseinfo/toAddPage.do?fncInsId='+selectedRows[0].id,
        });
	}
	
	//融资机构-流程信息
	function loadFlow(){
		var selectedRows = grid.getSelectedRows();
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
            return;
        }
		$.ligerDialog.SQopen({
            cls: 'noBorder_Dialog',
            width: 800,
            height:500,
            title : '融资机构-流程信息',
            url:'<%=path%>/rfbase/fribaseinfo/toFriBaseFlow.do?id='+selectedRows[0].id,
        });
	}
	
	//pre-abs来款记录
	function preabs(){
		var selectedRows = grid.getSelectedRows();
        if (selectedRows.length != 1) {
            $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
            return;
        }
        var callback = function(){
			// grid.reload();
		}
	var params="?id="+selectedRows[0].id;

		Add_navTab('fnc_pre_abs_'+selectedRows[0].id,'机构账户额度管理','<%=path%>/rfbuss/fncpreabslim/toListPage.do'+params,callback);
	
	}
	
	
	//融资机构-查看授信
	function searchCr(_id){
		$.ligerDialog.SQopen({
            cls: 'noBorder_Dialog',
            width: 1100,
            height:500,
            title : '融资机构-查看授信',
            url:'<%=path%>/rfbase/crbaseinfo/toListPage.do?fncInsId='+_id,
        });
	}
	
	//融资机构-查看融资报价
	function searchScm(_id){
		$.ligerDialog.SQopen({
            cls: 'noBorder_Dialog',
            width: 1100,
            height:500,
            title : '融资机构-查看融资报价',
            url:'<%=path%>/rfbase/scmbaseinfo/toListPage.do?fncInsId='+_id,
        });
	}
	
	//发起审核流程
	function startFlow(_id){
		if(!_id)return;
		var modelTyp ="R003";//流程业务分类-再融资融资机构审核
		if(StringUtils.isEmpty(modelTyp)){
			console.log("modelTyp is null");
			return;
		}
        var flowDialog = $.ligerDialog.SQopen({
            url: '<%=path%>/flow/flow/toForStartListPage.do?modelTyp='+modelTyp,
            width: 700,
            height:400,
            title : '请选择要发起的流程',
            buttons: [{
	                text: "确定", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ],
            onClose: function () {
            	var json = flowDialog._DATA;
            	console.log(json);
            	if(!json){
                	return;
            	}
            	var wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting",onClose: function () {}});
        		$.ajax({
            		type: 'post',
            		dataType:'json',
            		data:{
            			id:_id,
            			procDefKey:json.procDefKey,
            			procDefId:json.procDefId,
            			procNo:json.procNo
            		},
            		url: '<%=path%>/rfbase/fribaseinfo/addFlowStart.do',
					success : function(msg) {
						wait_dialog.close();
						if (msg.success == 1) {
							UIUtils.alertSuccessHold1(msg.info);
							grid.reload();
						} else {
							UIUtils.alertErrorHold1(msg.info);
						}
					}
				});
			}
		});
	}

	//格式化时间
	function renderDate(rowdata, index, value) {
		var dateStr = "";
		if (null != value) {
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}

	//清空按钮事件
	function clearBtn() {
		$("#resetBtn").click(); //重置 input-text
		var form = new liger.get("searchBar");
		form.setData({ //重置select等特殊表单
			"fundRasInsNm" : "",
			"insSts" : "",
			"stDt" : "",
			"edDt" : "",
			"crSt" : "",
			"insUseCd":"",
			"insUseCdNm":"",
			"isBa":""
		});
	}

	function iframeResize() {
		if (parent.mainApp) {
			parent.mainApp.parentTab.onResize();
		}
	}

	//数字格式转换成千分位
	function commafy(rowdata, index, s) {
		if(null == s) return;
		return formatMoney(s);
	}

	function formatMoney(number, places, symbol, thousand, decimal) {
		number = number || 0;
		places = !isNaN(places = Math.abs(places)) ? places : 2;
		// symbol = symbol !== undefined ? symbol : "$";
		symbol = symbol !== undefined ? symbol : "";
		thousand = thousand || ",";
		decimal = decimal || ".";
		var negative = number < 0 ? "-" : "", 
			i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10)+ "",
			j = (j = i.length) > 3 ? j % 3 : 0;
		return symbol
				+ negative
				+ (j ? i.substr(0, j) + thousand : "")
				+ i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand)
				+ (places ? decimal
				+ Math.abs(number - i).toFixed(places).slice(2) : "");
	}
	//跳转到维护机构详情
	function modifyDetail(_id){
		parent.mainApp.f_addTab('friBaseInfo'+_id,'金融机构详情','<%=path%>/rfbase/fribaseinfo/modifyDetailPage.do?id='+_id);
	}
</script>

<body class="iframeBody">
	<div class="Wrapper">
		<div class="searchArea">
			<form id="searchBar">
				<div class="fieldset1 clearFix">
					<div class="fieldBox">
						<div class="label">融资机构名称</div>
						<div class="field">
							<input name="fundRasInsNm" id="fundRasInsNm" type="text" class="ui-textbox" value="">
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">机构状态</div>
						<div class="field">
							<select name="insSts" id="insSts" data-value=" ">
								<option value=" " seleted>请选择</option>
								<c:forEach items="${insStsList }" var="kv">
									<option value="${kv.key }">${kv.value }</option>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">授信状态</div>
						<div class="field">
							<select name="crSt" id="crSt" data-value=" ">
								<option value=" " seleted>请选择</option>
								<c:forEach items="${crStList }" var="kv">
									<option value="${kv.key }">${kv.value }</option>
								</c:forEach>
							</select>
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">授信期限</div>
						<div class="field">
							<input name="stDt" id="stDt" type="text" class="ui-datepicker" value="">
							-
							<input name="edDt" id="edDt" type="text" class="ui-datepicker" value="">
						</div>
					</div>
					<div class="fieldBox">
						<div class="label">机构用途：</div>
						<div class="field">
							<input type="text"  name="insUseCdNm" id="insUseCdNm"  class="ui-textbox" >
							<input type="hidden" name="insUseCd" id="insUseCd" data-ligerid="insUseCdNm" value="">
						</div>
					</div>
					<div class="fieldBox">
                <div class="label">授信是否已备案</div>
                <div class="field">
                    <select name="isBa" id="isBa" data-value=" ">
                       <option value="" selected="selected">请选择</option>
                       <option value="1" >是</option>
                       <option value="0" >否</option>
                       
                    </select>
                </div>
            </div>
					<div class="clearFix"></div>
					<div class="btnsBox formBtns notRight">
						<span id="searchBtn" class="sq-button-round">查询</span>
						<span id="clearBtn" class="sq-button-round" onclick="clearBtn();">清空</span>
						<span id="addBtn" class="sq-button-round" onclick="add();">添加机构</span>
						<span id="" class="sq-button-round" onclick="addCr();">添加授信</span>
						<span id="" class="sq-button-round" onclick="addScm();">添加报价</span>
						<input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide" />
						<span id="" class="sq-button-round" onclick="loadFlow()">流程信息</span>
						<span id="" class="sq-button-round" onclick="preabs()">PRE-ABS来款记录</span>
					</div>
			</form>
		</div>
	</div>
	<div id="ligergrid1" class="sq-grid"></div>


</body>
</html>
